package com.vcredit.creditcat.service.speedloan;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.dto.product.h5.CheckOrderResultDto;
import com.vcredit.creditcat.dto.speedloan.CheckCustResultDto;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.model.ProductCheckcustItem;
import com.vcredit.creditcat.service.ProductApiUrlService;
import com.vcredit.creditcat.service.product.h5.AfterCreditService;
import com.vcredit.framework.annotation.Log;

@Service
public class CommonCheckCustServiceImpl extends CommonProductCheckCustService {
	
	private static final Logger LOG = LoggerFactory.getLogger(CommonCheckCustServiceImpl.class);
	
	@Autowired
	private ProductApiUrlService productApiUrlService;
	@Autowired
	private AfterCreditService afterCreditService;
	
	@Log
	@Override
	public CheckCustResultDto handlerCheckItem(ProductCheckcustItem checkItem,
			int itemType, Cust cust, Long productId) {
		int checkItemId = checkItem.getCheckItemId();
		if(itemType == 0) { // 原始认证项
			switch (checkItemId) {
			case 1:
				try {
					CheckOrderResultDto checkResult = afterCreditService.checkUser(productId, cust);
					if(checkResult.getCanLoanFlag()) {
						return CheckCustResultDto.success();
					} else {
						return CheckCustResultDto.fail(checkResult.getFailTips());
					}
				} catch (Exception e) {  //接口异常默认通过，防止网络等原因影响后续流程
					LOG.error("------------统一的交单校验出错!! productId="+productId+",custId="+cust.getCustId(), e);
					return CheckCustResultDto.success();
				} 
			default:
				break;
			}
		} else { // 补充认证项
			switch (checkItemId) {
			case 1:
				// 执行信用花基本信息完成后的校验规则
				break;
			case 2:
				// 执行信用花的手机认证完成后的校验规则
				break;

			default:
				break;
			}
		}
		
		return CheckCustResultDto.success();
	}
}
